//
//  DiarySecondTableViewCell.m
//  土巴兔
//
//  Created by 千锋 on 16/1/5.
//  Copyright (c) 2016年 IOS1503薛凯. All rights reserved.
//

#import "DiarySecondTableViewCell.h"
#import "UIButton+WebCache.h"
#import "UIImageView+WebCache.h"
#import "Default.h"
@implementation DiarySecondTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createUI];
    }
    
    return self;
}
#pragma mark- 创建页面的布局格式
- (void) createUI{
    
    //设置背景
    _bgImage=[[UIImageView alloc] initWithFrame:CGRectMake(10, 5, DEVICEWIDTH-20,240)];
    _bgImage.backgroundColor=[UIColor whiteColor];
    _bgImage.layer.cornerRadius=5;
//    [_bgImage setImage:[UIImage imageNamed:@"bg_bbsProgress"]];
    [self.contentView addSubview:_bgImage];
    //人气标签
    _toptag_nameBtn=[[UIButton alloc] initWithFrame:CGRectMake(10, 10, 50, 13)];
    _toptag_nameBtn.titleLabel.font=[UIFont systemFontOfSize:12];
    [_toptag_nameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    _toptag_nameBtn.backgroundColor=[UIColor redColor];
    [self.contentView addSubview:_toptag_nameBtn];
//    @property (strong,nonatomic)UIButton* toptag_nameBtn;//人气标签
    //头像
    _headerBtn=[[UIButton alloc] initWithFrame:CGRectMake(15, 28, 33, 32)];
    [_headerBtn setBackgroundImage:[UIImage imageNamed:@"ico_headPortrait_162"] forState:UIControlStateNormal];
    _headerBtn.clipsToBounds=YES;
//    _headerBtn.backgroundColor=[UIColor redColor];
    _headerBtn.layer.cornerRadius=16;
    [self.contentView addSubview:_headerBtn];
//    @property (strong,nonatomic)UIButton* headerBtn;//头像
    //主标题
    _nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 27, 250, 20)];
    _nameLabel.font=[UIFont systemFontOfSize:15];
    [self.contentView addSubview:_nameLabel];
//    @property (strong,nonatomic)UILabel* nameLabel;//主标题
    //副标题
    _subLabel=[[UILabel alloc] initWithFrame:CGRectMake(60, 45, 200, 20)];
    _subLabel.font=[UIFont systemFontOfSize:13];
    _subLabel.textColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
    [self.contentView addSubview:_subLabel];
//    @property (strong,nonatomic)UILabel* subLabel;//副标题 (15.2万/254m/复式/简约)
    
    //装修类型
    _small_tag_nameBtn=[[UILabel alloc] initWithFrame:CGRectMake(DEVICEWIDTH-70, 45, 30, 20)];
    _small_tag_nameBtn.layer.cornerRadius=3;
    _small_tag_nameBtn.clipsToBounds=YES;
    _small_tag_nameBtn.textAlignment=NSTextAlignmentCenter;
    _small_tag_nameBtn.font=[UIFont systemFontOfSize:14];
    _small_tag_nameBtn.backgroundColor=[UIColor colorWithRed:34.0/255 green:139.0/255 blue:34.0/255 alpha:1];
    _small_tag_nameBtn.textColor=[UIColor whiteColor];
    [self.contentView addSubview:_small_tag_nameBtn];
//    @property (strong,nonatomic)UIButton* small_tag_nameBtn;//装修类型(墙面烤漆)
    //日记内容
    _diary_contentLabel=[[UILabel alloc] initWithFrame:CGRectMake(15, 65, DEVICEWIDTH-30, 65)];
    _diary_contentLabel.numberOfLines=0;
    _diary_contentLabel.textColor=[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.7];
    _diary_contentLabel.font=[UIFont systemFontOfSize:13];
    [self.contentView addSubview:_diary_contentLabel];
//    @property (strong,nonatomic)UILabel* diary_contentLabel;//日记内容
    //日记图片
    _diary_imageFirst=[[UIImageView alloc]initWithFrame:CGRectMake(15, 140, (DEVICEWIDTH-50)/3, 70)];
    [self.contentView addSubview:_diary_imageFirst];
    _diary_imageSecond=[[UIImageView alloc]initWithFrame:CGRectMake(25+(DEVICEWIDTH-50)/3, 140, (DEVICEWIDTH-50)/3, 70)];
    [self.contentView addSubview:_diary_imageSecond];
    _diary_imageThirs=[[UIImageView alloc]initWithFrame:CGRectMake(35+(DEVICEWIDTH-50)/3*2, 140, (DEVICEWIDTH-50)/3, 70)];
    [self.contentView addSubview:_diary_imageThirs];
    //    @property (strong,nonatomic)UIImageView *diary_imageFirst;
//    @property (strong,nonatomic)UIImageView *diary_imageSecond;
//    @property (strong,nonatomic)UIImageView *diary_imageThirs;
    //浏览次数
    _view_numBtn=[[UIButton alloc] initWithFrame:CGRectMake(20, 220, 55, 15)];
    [_view_numBtn setImage:[UIImage imageNamed:@"ico_guanzhu_gray"] forState:UIControlStateNormal];
    _view_numBtn.imageEdgeInsets=UIEdgeInsetsMake(0, -10, 0, 0);
    _view_numBtn.titleLabel.font=[UIFont systemFontOfSize:13];
    [_view_numBtn setTitleColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8] forState:UIControlStateNormal];
    [self.contentView addSubview:_view_numBtn];
    
//    @property (strong,nonatomic)UIButton *view_numBtn;//浏览次数
    //评论次数
    _comment_number=[[UIButton alloc] initWithFrame:CGRectMake(80, 222, 55, 13)];
    [_comment_number setImage:[UIImage imageNamed:@"ico_common_line"] forState:UIControlStateNormal];
    _comment_number.imageEdgeInsets=UIEdgeInsetsMake(0, -10, 0, 0);
    _comment_number.titleLabel.font=[UIFont systemFontOfSize:13];
    [_comment_number setTitleColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8] forState:UIControlStateNormal];
    [self.contentView addSubview:_comment_number];
//    @property (strong,nonatomic)UIButton* comment_number;//评论次数
    //发布时间
    _recent_time=[[UIButton alloc] initWithFrame:CGRectMake(220, 220, 90, 15)];
    _recent_time.titleLabel.font=[UIFont systemFontOfSize:13];
    [_recent_time setTitleColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8] forState:UIControlStateNormal];
//    _recent_time.backgroundColor=[UIColor blueColor];
    [self.contentView addSubview:_recent_time];
//    @property (strong,nonatomic)UIButton* recent_time;//发布时间
}
#pragma mark- 根据model更新数据函数接口
- (void)relayoutWithModel:(DiarySecondModel*)model{
//    @property (strong,nonatomic)UIButton* toptag_nameBtn;//人气标签
    if (model.toptag_name.length==0) {
        _toptag_nameBtn.hidden=YES;
    }
    [_toptag_nameBtn setTitle:model.toptag_name forState:UIControlStateNormal];
//    @property (strong,nonatomic)UIButton* headerBtn;//头像
    if (model.owner_avatar.length==0) {
        [_headerBtn setBackgroundImage:[UIImage imageNamed:@"ico_headPortrait_100"] forState:UIControlStateNormal];
    }else{
        [_headerBtn sd_setBackgroundImageWithURL:[NSURL URLWithString:model.owner_avatar] forState:UIControlStateNormal];
    }
//    @property (strong,nonatomic)UILabel* nameLabel;//主标题
    [_nameLabel setText:model.name];
//    @property (strong,nonatomic)UILabel* subLabel;//副标题 (15.2万/254m/复式/简约)
    if (model.style.count>0) {
        [_subLabel setText:[NSString stringWithFormat:@"%d万/%dm/%@",[model.product_price intValue],[model.area intValue],model.style[0]]];
    }else{
        [_subLabel setText:[NSString stringWithFormat:@"%d万/%dm/",[model.product_price intValue],[model.area intValue]]];
    }
//    @property (strong,nonatomic)UIButton* small_tag_nameBtn;//装修类型(墙面烤漆)
    [_small_tag_nameBtn setText:model.small_tag_name];
    _small_tag_nameBtn.bounds=CGRectMake(0, 0, 16*model.small_tag_name.length, 18);
//    @property (strong,nonatomic)UILabel* diary_contentLabel;//日记内容
    [_diary_contentLabel setText:model.diary_content];
    if (model.diary_image.count==1) {
        [_diary_imageFirst sd_setImageWithURL:model.diary_image[0]];
    }else if (model.diary_image.count==2){
        [_diary_imageFirst sd_setImageWithURL:model.diary_image[0]];
        [_diary_imageSecond sd_setImageWithURL:model.diary_image[1]];
    }else if (model.diary_image.count==3){
        [_diary_imageFirst sd_setImageWithURL:model.diary_image[0]];
        [_diary_imageSecond sd_setImageWithURL:model.diary_image[1]];
        [_diary_imageThirs sd_setImageWithURL:model.diary_image[2]];
    }
//    @property (strong,nonatomic)UIImageView *diary_imageFirst;
//    @property (strong,nonatomic)UIImageView *diary_imageSecond;
//    @property (strong,nonatomic)UIImageView *diary_imageThirs;
//    @property (strong,nonatomic)UIButton *view_numBtn;//浏览次数
    [self.view_numBtn setTitle:[NSString stringWithFormat:@"%@",model.view_num] forState:UIControlStateNormal];
//    @property (strong,nonatomic)UIButton* comment_number;//评论次数
    [self.comment_number setTitle:[NSString stringWithFormat:@"%@",model.comment_number] forState:UIControlStateNormal];
//    @property (strong,nonatomic)UIButton* recent_time;//发布时间
    [self.recent_time setTitle:model.recent_time forState:UIControlStateNormal];

}
@end
